/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nominalitzacions.ui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import javax.swing.text.Highlighter.Highlight;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import nominalitzacions.domain.CorrectWordDomainController;
import nominalitzacions.domain.UrlDomainController;



/**
 *
 * @author sonia.sandalinas
 */
public class PrincipalView extends JFrame
{
    
   private PrincipalViewController PVC;
   
   private JPanel mainPanel = new JPanel();
   private JPanel buttonPanel = new JPanel();
   private JPanel comboPanel = new JPanel();
   private JPanel textPanel = new JPanel();
   
   //button
   private JButton idenVerb = new JButton("Verb Identifier");
   
   //combo
   private GraphicsEnvironment fonts = GraphicsEnvironment.getLocalGraphicsEnvironment();
   private String[] f = fonts.getAvailableFontFamilyNames();
   
   private String[] s = { "12", "14", "16", "18", "20" };
   
   private String[] c = { "Green", "Blue", "Gray", "Black" };
   
   private JComboBox langCombo = new JComboBox();
   private JComboBox fontCombo = new JComboBox(f);
   private JComboBox sizeCombo = new JComboBox(s);
   private JComboBox colorCombo = new JComboBox(c);
   //private JLabel lang = new JLabel("Language :");
   private JLabel font = new JLabel("Font :");
   private JLabel size = new JLabel("Size :");
   private JLabel color = new JLabel("Color :");
   
   //text
   private JTextPane text = new JTextPane();
   private int v = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
   private int h = JScrollPane.HORIZONTAL_SCROLLBAR_NEVER;
   private JScrollPane textScroll = new JScrollPane(text, v, h); 
   private JList list = new JList();
   private JScrollPane listScroll = new JScrollPane(list, v, h);
   
   //Menu
   private JMenuBar menuBar = new JMenuBar();

   private JMenu file = new JMenu("File");
   private JMenuItem newFile = new JMenuItem("New");
   private JMenu open = new JMenu("Open");
   private JMenuItem textOpen = new JMenuItem("Text");
   private JMenuItem projectOpen = new JMenuItem("Project");
   private JMenu save = new JMenu("Save");
   private JMenuItem textsSave = new JMenuItem("Text");
   private JMenuItem projectsSave = new JMenuItem("Project");
   private JMenuItem exit = new JMenuItem("Exit");
   private JMenu edit = new JMenu("Edit");
   private JMenuItem corpusEdit = new JMenu("Corpus");
   private JMenuItem addPair = new JMenuItem("Add Pair");
   private JMenuItem removePair = new JMenuItem("Remove Pair");
   private JMenuItem diccEdit = new JMenu("Dictionary");
   private JMenuItem addDicc = new JMenuItem("Add");
   private JMenuItem removeDicc = new JMenuItem("Remove");
   private JMenuItem confEdit = new JMenuItem("Settings");
   private JMenuItem redefEdit = new JMenuItem("ChangePassword");
   private JMenu help = new JMenu("Help");
   private JMenuItem manHelp = new JMenuItem("Manual");
   private JMenuItem authorsHelp = new JMenuItem("Authors");
   private JMenuItem featuresHelp = new JMenuItem("Features");

   private int startoff = 0;
   private Highlighter hilit;
   private Highlighter.HighlightPainter painter;

   private UrlDomainController UDC;

   public PrincipalView(PrincipalViewController PVC){
       this.PVC = PVC;
       iniComponents();
       
        hilit = new DefaultHighlighter();
        painter = new DefaultHighlighter.DefaultHighlightPainter(Color.GREEN);
	text.setHighlighter(hilit);
   }
   
   private void iniComponents(){

        iniFrame();
        iniMain();
        assigListeners();
   }
   
   private void iniFrame(){
        this.setMinimumSize(new Dimension(800, 600));
        this.setTitle("Nominalized");
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        JPanel contentPane = (JPanel) this.getContentPane();
        contentPane.add(mainPanel);
        //this.setLayout(null);
   }
   
   private void iniMain(){
       buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
       idenVerb.setPreferredSize(new Dimension(800, 35));
       buttonPanel.add(idenVerb);
       
       textPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
       text.setPreferredSize(new Dimension(600,500));
        textPanel.add(textScroll);
        list.setPreferredSize(new Dimension(200,500));
        list.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        textPanel.add(list);
        
       fontCombo.setSelectedItem("Times New Roman");
       colorCombo.setSelectedItem("Black");
       GroupLayout layout = new GroupLayout(comboPanel);
        comboPanel.setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        GroupLayout.SequentialGroup heightGroup = layout.createSequentialGroup();
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(font));
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(fontCombo));
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(size));
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(sizeCombo));
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(color));
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(colorCombo));
        layout.setHorizontalGroup(heightGroup);

        GroupLayout.SequentialGroup verGroup = layout.createSequentialGroup();
        verGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
                .addComponent(font)
                .addComponent(fontCombo)
                .addComponent(size)
                .addComponent(sizeCombo)
                .addComponent(color)
                .addComponent(colorCombo));
        layout.setVerticalGroup(verGroup);
        
        setJMenuBar(menuBar);
        menuBar.add(file);
        file.add(newFile);
        file.add(open);
        open.add(textOpen);
        file.add(save);
        save.add(textsSave);
        file.add(exit);
        menuBar.add(edit);
        edit.add(corpusEdit);
        corpusEdit.add(addPair);
        corpusEdit.add(removePair);
        edit.add(diccEdit);
        diccEdit.add(addDicc);
        diccEdit.add(removeDicc);
        edit.add(confEdit);
        edit.add(redefEdit);
        menuBar.add(help);
        help.add(manHelp);
        help.add(authorsHelp);
        help.add(featuresHelp);
        
        mainPanel.setLayout(new BorderLayout());
        //mainPanel.add(comboPanel, BorderLayout.NORTH);
        mainPanel.add(textPanel, BorderLayout.CENTER);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);

   }
   
   private void assigListeners(){
        sizeCombo.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPerformedSize();
            }
        });
        fontCombo.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPeformedFont();
            }
	});
        colorCombo.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPerformedColor();
            }
	});
        idenVerb.addActionListener(new ActionListener(){
            public void actionPerformed (ActionEvent evento){
                try {
                   int[][] marcar = actionPerformedIdentificarverb();
                } catch (BadLocationException ex) {
                    Logger.getLogger(PrincipalView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        //--------------------------------------------------------------
        newFile.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPerformedNewText();
            }
        });
        textOpen.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPerformedOpenText();
            }
        });
        textsSave.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPerformedSaveText();
            }
        });
        exit.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                System.exit(0);
            }
        });
        // ---------------------------------------------------------------

        redefEdit.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPerformedRedefinir();
            }
	});
        confEdit.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                actionPerformedSetting(); 
            }
	});
        addPair.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent evento) {
                loginAdmin("addPair");
            }
        });
        removePair.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent evento) {
                loginAdmin("removePair");
            }
        });
        addDicc.addActionListener(new ActionListener(){
            public void actionPerformed (ActionEvent evento){
                loginAdmin("addDicc");
            }
        });
        removeDicc.addActionListener(new ActionListener(){
            public void actionPerformed (ActionEvent evento){
                loginAdmin("removeDicc");
            }
        });
        //----------------------------------------------------------------
        manHelp.addActionListener(new ActionListener(){
            public void actionPerformed (ActionEvent evento){
                try {
                    actionPerformedHelp("M");
                } catch (IOException ex) {
                    String msg = ex.getMessage();
                    JOptionPane.showMessageDialog(new JPanel(), msg, "Error writing",
                                                    JOptionPane.ERROR_MESSAGE);
                } catch (URISyntaxException ex) {
                    String msg = ex.getMessage();
                    JOptionPane.showMessageDialog(new JPanel(), msg, "Error writing",
                                                    JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        authorsHelp.addActionListener(new ActionListener(){
            public void actionPerformed (ActionEvent evento){
                try {
                    actionPerformedHelp("A");
                } catch (IOException ex) {
                    String msg = ex.getMessage();
                    JOptionPane.showMessageDialog(new JPanel(), msg, "Error writing",
                                                    JOptionPane.ERROR_MESSAGE);
                } catch (URISyntaxException ex) {
                    String msg = ex.getMessage();
                    JOptionPane.showMessageDialog(new JPanel(), msg, "Error writing",
                                                    JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        featuresHelp.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent evento){
                try {
                    actionPerformedHelp("F");
                } catch (IOException ex) {
                    String msg = ex.getMessage();
                    JOptionPane.showMessageDialog(new JPanel(), msg, "Error writing",
                                                    JOptionPane.ERROR_MESSAGE);
                } catch (URISyntaxException ex) {
                    String msg = ex.getMessage();
                    JOptionPane.showMessageDialog(new JPanel(), msg, "Error writing",
                                                    JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        //------------------------------------------------------------------
        text.addMouseListener(new MouseListener(){
            public void mouseClicked(MouseEvent e){
                addList();
            }
            public void mousePressed(MouseEvent e){
            }
            public void mouseReleased(MouseEvent e) {
            }
            public void mouseEntered(MouseEvent e){			
            }
            public void mouseExited(MouseEvent e){   
            }
        });

    MouseListener mouseListener = new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                int index = list.locationToIndex(e.getPoint());
                    try {
                        addTextSelected();
                        int[][] marcar = actionPerformedIdentificarverb();
                    } catch (BadLocationException ex) {
                        Logger.getLogger(PrincipalView.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        };
    list.addMouseListener(mouseListener);

   }  
   
   private void loginAdmin(String what){
       PVC.viewLoginAdmin(what);
   }
   
   private void actionPerformedSize(){
        String selec = (String)sizeCombo.getSelectedItem();
        int sizeOne = Integer.valueOf(selec);
        MutableAttributeSet attr = new SimpleAttributeSet();
        StyleConstants.setFontSize(attr, sizeOne);
        text.setCharacterAttributes(attr, false);
   }
   
   private void actionPeformedFont(){
        String selec = (String)fontCombo.getSelectedItem();
        MutableAttributeSet attr = new SimpleAttributeSet();
        StyleConstants.setFontFamily(attr, selec);
        text.setCharacterAttributes(attr, false);
   }
   
   private void actionPerformedColor(){
        String selec = (String)colorCombo.getSelectedItem();
        Color nuevo = null;
                if (selec.equals("Green")) nuevo = Color.GREEN;
                if (selec.equals("Blue")) nuevo = Color.BLUE;
                if (selec.equals("Gray")) nuevo = Color.LIGHT_GRAY;
                if (selec.equals("Black")) nuevo = Color.BLACK;
                MutableAttributeSet attr = new SimpleAttributeSet();
                StyleConstants.setForeground(attr, nuevo);
        text.setCharacterAttributes(attr, false);
   }
   
   private int[][]actionPerformedIdentificarverb() throws BadLocationException{
        hilit.removeAllHighlights();
        String texto = text.getDocument().getText(0, text.getDocument().getLength() );
        int[][] marcar = null;
        try {
            marcar = PVC.sendText(texto);
        } catch (IOException ex) {
            String msg = ex.getMessage();
            JOptionPane.showMessageDialog(this, msg, "Error",
                      JOptionPane.ERROR_MESSAGE);
        }
            for (int i = 0; i < marcar.length && marcar[i][0] != -1 ;++i) {
            try {
                hilit.addHighlight(marcar[i][1], marcar[i][0], painter);
            } catch (BadLocationException ex) {
                String msg = ex.getMessage();
                JOptionPane.showMessageDialog(this, msg, "Error",
                      JOptionPane.ERROR_MESSAGE);
            }
        }
        return marcar;
    }
   
    private void actionPerformedNewText(){
	text.setText("");
    }
    
    private void actionPerformedOpenText(){
        JFileChooser otext = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("archivos .txt", "txt");
        otext.setFileFilter(filter);
        int seleccion = otext.showOpenDialog(null);
        if (seleccion == JFileChooser.APPROVE_OPTION){
            File fileToOpen = otext.getSelectedFile();
            String Opentext = fileToOpen.getPath();
            String openI = PVC.sendPath(Opentext);
            text.setText(openI);
        }
    }
    
    private void actionPerformedSaveText(){
	JFileChooser otext =new JFileChooser();
        String nombre = "";
        FileNameExtensionFilter filter = new FileNameExtensionFilter("archivos .txt","txt");
        otext.setFileFilter(filter);
        otext.showSaveDialog(null);
        File GUARDAR =otext.getSelectedFile();
        if(GUARDAR != null) {
            FileWriter GUARDADO = null;
            try {
                nombre = otext.getSelectedFile().getName();
                GUARDADO = new FileWriter(GUARDAR);
                GUARDADO.write(text.getText());
                GUARDADO.close();
            } catch (IOException ex) {
                Logger.getLogger(PrincipalView.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    GUARDADO.close();
                } catch (IOException ex) {
                    Logger.getLogger(PrincipalView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        }
    }
    
    private void actionPerformedRedefinir(){
        PVC.ViewRedefinir();
    }
    
    private void actionPerformedHelp(String s) throws IOException, URISyntaxException{
        Desktop desktop = null;
        UDC = new UrlDomainController();
	if(s.equals("M")) {
            desktop = Desktop.getDesktop();
            desktop.browse( (new File(UDC.gotRes() + "Manual.html") ).toURI() );
        }
        else if(s.equals("A")){
            desktop = Desktop.getDesktop();
            desktop.browse( (new File(UDC.gotRes() + "Authors.html") ).toURI() );
        }
        else {
            desktop = Desktop.getDesktop();
            desktop.browse( (new File(UDC.gotRes() + "Features.html") ).toURI() );
        }
    }
    
    private void actionPerformedSetting() {
        try {
            PVC.ViewSettings();
        }
        catch (FileNotFoundException ex){
            String msg = ex.getMessage();
            JOptionPane.showMessageDialog(this, msg, "Error",
                    JOptionPane.ERROR_MESSAGE);
            }
    }
    private void addList(){
        Point cursor = text.getMousePosition();
        text.getComponentAt(cursor);
        int off = text.viewToModel(cursor);
        String word = "";
        int wordStart = 0;
        int wordEnd = 0;
        boolean esta = false;
        Highlight[] h = hilit.getHighlights();
        for (int i = 0; i < h.length && !esta; ++i){
            if (h[i].getEndOffset() <= off && h[i].getStartOffset() >= off) {
                esta = true;
                wordStart = h[i].getStartOffset();
                wordEnd = h[i].getEndOffset();
            }
        }
        startoff = wordStart;
        System.out.println("WordStart : " + wordStart);
        System.out.println("WordEnd : " + wordEnd);
        try {
            word = text.getDocument().getText(wordEnd, wordStart-wordEnd);
            System.out.println("Paraula : "+ word);
         } catch (BadLocationException ex) {
            
        }
        if (esta) {
            ArrayList<String> listaHere = null;
            try {
                listaHere = PVC.getCorrectList(word.toLowerCase() );
            } catch (IOException ex) {
                Logger.getLogger(PrincipalView.class.getName()).log(Level.SEVERE, null, ex);
            }

            DefaultListModel lista = new DefaultListModel();
            for(int k = 0; k < listaHere.size(); ++k){
                lista.addElement(listaHere.get(k));
            }
            //lista.copyInto(listaH.toArray() );
            list.setModel(lista);
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        }
        else {
            DefaultListModel listaHere = new DefaultListModel();
            list.setModel(listaHere);
        }
        System.out.println(list.getSelectedIndex());
    }

    private void actionPerformedPass() {
        PVC.ViewLogin();
    }
    private void addTextSelected() throws BadLocationException {
        String selected = (String) list.getSelectedValue();
        text.getDocument().insertString(startoff, "{"+ selected +"}", null);
        DefaultListModel listaHere = new DefaultListModel();
        list.setModel(listaHere);
    }

    
//
//	private PrincipalViewController PVC;
//
//	// Variable Texto principal
//	private JTextPane text = new JTextPane();
//	private int horizontal = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
//	private int vertical = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
//	private JScrollPane scroller = new JScrollPane(text, vertical, horizontal);
//
//	//Listas ComboBox
//	private String[] s = { "12", "14", "16", "18", "20" };
//	private String[] c = { "Green", "Blue", "Gray", "Black" };
//	private GraphicsEnvironment fonts = GraphicsEnvironment.getLocalGraphicsEnvironment();
//	private String[] f = fonts.getAvailableFontFamilyNames();
//	private JLabel tamany = new JLabel("Size");
//	private JComboBox size = new JComboBox(s);
//	private JLabel fuente1 = new JLabel("Source");
//	private JComboBox fuente = new JComboBox(f);
//	private JLabel color2 = new JLabel("Color");
//	private JComboBox color = new JComboBox(c);
//
//	//Lista nominalizaciones
//	private JList list  = new JList(/*new DefaultListModel()*/);
//
//	//Menu
//	private JMenuBar menuBar = new JMenuBar();
//
//	private JMenu file = new JMenu("File");
//	private JMenuItem new1 = new JMenuItem("New");
//	private JMenu open = new JMenu("Open");
//	private JMenuItem text1 = new JMenuItem("Text");
//	private JMenuItem project = new JMenuItem("Project");
//	private JMenu save = new JMenu("Save");
//	private JMenuItem texts = new JMenuItem("Text");
//	private JMenuItem projects = new JMenuItem("Project");
//	private JMenuItem exit = new JMenuItem("Exit");
//	private JMenu edit = new JMenu("Edit");
//	private JMenuItem idiom = new JMenuItem("Idiom");
//	private JMenuItem corpus = new JMenuItem("Corpus");
//	private JMenuItem dicc = new JMenuItem("Dictionary");
//	private JMenuItem conf = new JMenuItem("Configuration");
//	private JMenuItem redef = new JMenuItem("ChangePassword");
//	private JMenu help = new JMenu("Help");
//	private JMenuItem man = new JMenuItem("Manual");
//	private JMenuItem authors = new JMenuItem("Authors");
//	private JMenuItem features = new JMenuItem("Features");
//        private String ultim;
//
//
//	private int lastPost = 0;
//	private int n;
//
//	private final Highlighter hilit;
//	private final Highlighter.HighlightPainter painter;
//
//
//	/*private JMenu apareance = new JMenu("Appareance");
//        private JMenu background = new JMenu("background");
//			private JMenuItem blue = new JMenuItem ("Blue");
//			private JMenuItem red = new JMenuItem("Red");
//			private JMenuItem yellow = new JMenuItem("Yellow");
//			private JMenuItem green = new JMenuItem ("Green");
//			private JMenuItem black = new JMenuItem ("Black");
//			private JMenuItem white = new JMenuItem ("White");
//			private JMenuItem gray = new JMenuItem ("Gray");*/
//
//	//Botones
//	  private JButton idv = new JButton("VerbsIdentifier");
//      private JButton nmlt = new JButton("Nominalized");
//      private int[][] marcar;
//
//
//	public PrincipalView(PrincipalViewController PVC)
//	{
//		this.PVC = PVC;
//
//		iniComponents();
//		hilit = new DefaultHighlighter();
//		painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
//		text.setHighlighter(hilit);
//	}
//
//	private void iniComponents()
//	{
//		iniFrame();
//		iniAll();
//		assigListeners();
//	}
//
//	private void iniFrame()
//	{
//		this.setMinimumSize(new Dimension(800, 600));
//		this.setTitle("nominalized");
//		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//		this.setResizable(true);
//		this.setLocationRelativeTo(null);
//		this.setLayout(null);
//	}
//
//	private void iniAll()
//	{
//		//ComboBox
//		size.setBounds(720, 20, 50, 20);
//		this.add(size);
//		tamany.setBounds(680, 20, 50, 30);
//		this.add(tamany);
//		size.setFocusable(false);
//		fuente.setBounds(340, 20, 200, 20);
//		this.add(fuente);
//		fuente.setFocusable(false);
//		fuente1.setBounds(290, 20, 50, 30);
//		this.add(fuente1);
//		fuente.setSelectedItem("Times New Roman");
//		color.setBounds(590, 20, 80, 20);
//		this.add(color);
//		color.setFocusable(false);
//		color2.setBounds(550, 20, 50, 30);
//		this.add(color2);
//		color.setSelectedItem("Black");
//
//		//Jtextpane
//		list.setBounds (580,50,200,460);
//        Border borde;
//        borde = BorderFactory.createEtchedBorder();
//        list.setBorder(borde);
//        this.add(list);
//		text.setBounds(30, 50, 540, 460);
//				text.requestFocus();
//				text.selectAll();
//				scroller.setBounds(30, 50, 540, 460);
//				this.add(scroller);
//		text.requestFocusInWindow();
//
//		//Menu
//		setJMenuBar(menuBar);
//		menuBar.add(file);
//		file.add(new1);
//		file.add(open);
//		open.add(text1);
//		open.add(project);
//		file.add(save);
//		save.add(texts);
//		save.add(projects);
//		file.add(exit);
//
//		menuBar.add(edit);
//		edit.add(idiom);
//		edit.add(corpus);
//		edit.add(dicc);
//		edit.add(conf);
//		edit.add(redef);
//
//		menuBar.add(help);
//		help.add(man);
//		help.add(authors);
//		help.add(features);
//
//
//
//		//PopUps
//		// int contador = 0;
//        //Boton
//
//
//		/*menuBar.add(apareance);
//            apareance.add(background);
//                background.add(white);
//                background.add(yellow);
//                background.add(red);
//                background.add(green);
//				background.add(blue);
//				background.add(gray);
//				background.add(black);
//*/
//				//Botones
//	    idv.setBounds(200,520, 150, 20);
//		this.add(idv);
//		nmlt.setEnabled(false);
//		nmlt.setBounds(360,520,150,20);
//        this.add(nmlt);
//	}
//
//	private void assigListeners()
//	{

//
//		project.addActionListener(new ActionListener()
//		{
//			public void actionPerformed(ActionEvent evento)
//			{
//				actionPerformedOpenProject();
//			}
//		});
//		projects.addActionListener(new ActionListener()
//		{
//			public void actionPerformed(ActionEvent evento)
//			{
//				actionPerformedSaveProject();
//
//
//			}
//		});
    
		
//		
//		
		
//		
//		
//
//
//		/*text.getDocument().addDocumentListener(new DocumentListener()
//		{
//			public void insertUpdate(DocumentEvent e)
//			{
//				 String texto = text.getText();
//                 int[][] marcar = PVC.sendText(texto);
//                 System.out.println("jkasfhnfghnashfgd");
//				 for (int i = 0; i < marcar.length && marcar[i][0] != -1 ;++i) {
//                    try {
//                        hilit.addHighlight(marcar[i][1], marcar[i][0], painter);
//                    } catch (BadLocationException ex) {
//                        Logger.getLogger(PrincipalView.class.getName()).log(Level.SEVERE, null, ex);
//                    }
//                 }
//										
//
//				
//				
//
//			}
//			public void removeUpdate(DocumentEvent e)
//			{
//				insertUpdate(e);
//
//			}
//			public void changedUpdate(DocumentEvent e)
//			{
//                insertUpdate(e);
//			}
//
//		});
//		
//
//		text.addMouseListener(new MouseListener()
//		{
//
//			public void mouseClicked(MouseEvent e)
//			{
//
//				addList();
//			}
//
//			public void mousePressed(MouseEvent e)
//			{
//
//			}
//
//			public void mouseReleased(MouseEvent e)
//			{
//
//			}
//
//						 public void mouseEntered(MouseEvent e)
//			{
//			
//			}
//
//			public void mouseExited(MouseEvent e)
//			{
//
//
//
//			}

//		});
//		idiom.addActionListener(new ActionListener()
//		{
//			public void actionPerformed(ActionEvent evento)
//			{
//				actionPerformedLogin();
//			}
//		});
//		corpus.addActionListener(new ActionListener()
//		{
//			public void actionPerformed(ActionEvent evento)
//			{
//				actionPerformedLogin();
//			}
//		});
//		dicc.addActionListener(new ActionListener()
//		{
//			public void actionPerformed(ActionEvent evento)
//			{
//				actionPerformedLogin();
//			}
//		});
//	}
//
//
//	/*text.addKeyListener(new KeyAdapter() {
//            @Override
//             public void keyPressed(KeyEvent evt) {
//                 
//                
//            }
//            });*/

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

//	private void addList()
//	{
//			Point cursor = text.getMousePosition();
//			text.getComponentAt(cursor);
//			int off = text.viewToModel(cursor);
//                        
//			boolean esta = false;
//			Highlight[] h = hilit.getHighlights();
//			for (int i = 0; i < h.length && !esta; ++i)
//			{
//				if (h[i].getEndOffset() <= off && h[i].getStartOffset() >= off)
//				{
//					esta = true;
//                                        System.out.println(esta);
//				}
//			}
//                                                   
//			if (esta)
//			{
//                        //String[] nominalitzacions = /*0PVC.getNominalitzacions(ultim)*/;
//
//        /*                for(int i = 0; i < nominalitzacions.length;++i) {
//                            popupMenu.add(nominalitzacions[i]);
//                        }*/
//                            System.out.println("SI");
//                            for(int i = 0; i < 5;++i) {
//                                JLabel run = new JLabel("iep");
//                                list.add(run);
//                                System.out.println(list.getComponentCount());
//                                
//                            }
//                             this.pack();
//                             this.repaint();
//                            //addNominalizator(list.getComponent(index), off);
//			}
//
//	}
//        private void addNominalizator (Component c, int index) {
//            System.out.println(c);
//            System.out.println(index);
//        }
//
//        private void selection() {
//                            
//        }
//	

//


//
//	private void actionPerformedOpenProject()
//	{
//		JFileChooser otext = new JFileChooser();
//		FileNameExtensionFilter filter = new FileNameExtensionFilter("archivos .txt", "txt");
//		otext.setFileFilter(filter);
//		otext.showOpenDialog(null);
//	}
//
	
//
//	private void actionPerformedSaveProject()
//	{
//		JFileChooser otext = new JFileChooser();
//		FileNameExtensionFilter filter = new FileNameExtensionFilter("archivos .txt", "txt");
//		otext.setFileFilter(filter);
//		otext.showSaveDialog(null);
//	}
//
//	private void actionPerformedIdiom()
//	{
//		PVC.ViewIdiom();
//	}

	
//	private void actionPerformedLogin()
//	{
//		//        PVC.ViewLogin();
//	}
//    private int[][]actionPerformedIdentificarverb() {
//        String texto = text.getText();
//                 marcar = PVC.sendText(texto);
//                 //System.out.println("jkasfhnfghnashfgd");
//				 for (int i = 0; i < marcar.length && marcar[i][0] != -1 ;++i) {
//                    try {
//                        hilit.addHighlight(marcar[i][1], marcar[i][0], painter);
//                    } catch (BadLocationException ex) {
//                        Logger.getLogger(PrincipalView.class.getName()).log(Level.SEVERE, null, ex);
//                    }
//                 }
//                 return marcar;
//    }
//	/*private void actionPerformedDictionary(){
//        PVC.ViewDictionary();
//    }*/
//	public void setVisible()
//	{
//		setVisible(true);
//	}
}
